<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
</head>
<body>
<div align="center">
    <form class="layui-form layui-form-pane" action="" lay-filter="example">
        <div class="layui-form-item">
            <label class="layui-form-label">角色名</label>
            <div class="layui-input-inline">
                <input type="text" name="roleName" lay-verify="required" placeholder="请输入" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit="" lay-filter="updater">修改</button>

        </div>
        <input type="hidden" name="roleId" lay-verify="required" autocomplete="off" class="layui-input">
    </form>
</div>
<script src="/static/layui/layui.js"></script>
<script src="/static/js/axios.js"></script>
<script>
    layui.use(['jquery', 'form', 'table'], function () {
        const $ = layui.$,
            form = layui.form;


        const cc = window.parent.updateRole;//获取上层修改的信息
        form.val('example', {//表单赋值
            "roleName": cc.roleName,
            "roleId": cc.roleId
        });
        //监听提交
        form.on('submit(updater)', function (data) {

            layer.open({
                type: 1,
                title: '最终的提交信息',
                content: "<p align='center'>确认修改吗?</p>",
                btn: ['确认', '取消'],
                btnAlign: 'c',//按钮居中
                btn1: function () {
                    $.ajax({
                        url: '/user-role/update_role',
                        type: 'post',
                        data: JSON.stringify(data.field),
                        dataType: 'json',
                        contentType: 'application/json',
                        success: function (result) {
                            if (result.code == 200) {
                                layer.msg("修改成功",{
                                    time: 2000
                                });
                            } else {
                                layer.msg("修改失败",{
                                    time: 2000
                                });
                            }
                        }
                        ,
                        error:function(result){
                            layui.msg(result.message,{
                                time: 2000
                            });
                        }
                    })
                    const index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                    window.parent.location.reload();
                },
                btn2: function () {
                    const index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index);
                    // window.parent.location.reload();
                }
            })
            return false;
        });

    })
</script>
</body>
</html>